<?php
require_once (dirname(dirname(dirname(__FILE__)))) . '/my/conf/config.php';
ob_start("ob_gzip");
$ip	= get_real_ip();

if (in_array($ip,array('58.246.36.210','116.236.205.22','180.168.100.194')))
{
	ini_set('display_errors', 'on');
	define('DEBUG', true);
}
else
{
	ini_set('display_errors', 'off');
	define('DEBUG', false);
} 


$m = isset($_REQUEST['m']) ? $_REQUEST['m'] : 'index';
$a = isset($_REQUEST['a']) ? $_REQUEST['a'] : 'index';

/*$per	= array(
	'classified'	=> array('release'),
	'article'		=> array('add'),
	'member'		=> array('login','menulist','register','logout','home','checkUsername'),
	'city'			=> array('getcitybypid'),
	'image'			=> array('verification'),
);

if (!isset($per[$m]) && !in_array($per[$m],$a)) errorHandle::apiNotFound($m, $a);
*/

$file		= $_SERVER['DOCUMENT_ROOT'] . "/app/api/$m.api.php";
$class		= $m . 'Api';
$method		= $a . 'Action';

file_exists($file) ? require_once $file	: errorHandle::fileNotFound($file);

class_exists($class)			|| errorHandle::classNotFound($class);
method_exists($class,$method)   || errorHandle::methodNotFound($method);


if (!isset($request['wid'])) $request['wid'] = '4';

$website	= base::init('website')->fetchRow(array('wid'=>$request['wid']));
$attr		= base::init('website')->getConfig($website['domain']);

try
{
    $app = new $class;
	$app->template();
	$app->template->template_dir	= ROOT . $attr['tempdir'];
	$app->template->compile_dir		= ROOT . $attr['tempdir']."template_c";
	$app->template->cache_dir		= ROOT . $attr['tempdir']."cache_c";
	$app->attr	= $attr;
    $app->website	= $website;
    $app->$method($request);
}
catch (Exception $e)
{
    errorHandle::error($e);
}
ob_end_flush();